﻿Imports OMANE.Common.UI

Namespace ViewModels
    Public Class ViewModelGraphModelProjection
        Inherits ViewModelCommand
        Implements IViewModelTabSection

        Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone
        Public Property Title As String Implements Common.UI.IViewModelTabSection.Title
        Public Property IsClosable As Boolean Implements IViewModelTabSection.IsClosable

        Sub New()
            '_YearAxisUnit = 5
            '_YearAxisMinimum = 2009
            '_YearAxisMaximum = 2026
        End Sub

        Public ReadOnly Property ROEGLOBAL As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim data As New ArrayList
                    With Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteIndicateur
                        For i As Integer = 0 To .ROE_resNetsFdsPropres.Length - 1
                            data.Add(New SimplePoint(i + startyear, .ROE_resNetsFdsPropres(i)))
                        Next
                    End With
                    ResetYearAxis(5, startyear - 1, startyear + data.Count + 1)
                    Return data
                Catch ex As Exception
                    ' Return TestData.SimpleData

                End Try
            End Get
        End Property
        Public ReadOnly Property ROEDC As IEnumerable
            Get
                Return ROEGLOBAL
            End Get
        End Property
        Public ReadOnly Property ROEINCAP As IEnumerable
            Get
                Return ROEGLOBAL
            End Get
        End Property

        Public ReadOnly Property NBCOTISANTGLOBAL As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim data As New ArrayList
                    With Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.ProjectionGenNAnnuelle
                        For i As Integer = 0 To .NbCotDC.Length - 1
                            data.Add(New SimplePoint(i + startyear, .NbCotINCINV(i) + .NbCotDC(i)))
                        Next
                    End With

                    Return data
                Catch ex As Exception
                    ' Return TestData.SimpleData
                End Try
            End Get
        End Property
        Public ReadOnly Property NBCOTISANTDC As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim data As New ArrayList
                    With Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.ProjectionGenNAnnuelle
                        For i As Integer = 0 To .NbCotDC.Length - 1
                            data.Add(New SimplePoint(i + startyear, .NbCotDC(i)))
                        Next
                    End With

                    Return data
                Catch ex As Exception
                    '  Return TestData.SimpleData
                End Try
            End Get
        End Property
        Public ReadOnly Property NBCOTISANTINCAP As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim data As New ArrayList
                    With Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.ProjectionGenNAnnuelle
                        For i As Integer = 0 To .NbCotDC.Length - 1
                            data.Add(New SimplePoint(i + startyear, .NbCotINCINV(i)))
                        Next
                    End With
                    Return data
                Catch ex As Exception
                    '  Return TestData.SimpleData
                End Try
            End Get
        End Property

        Public ReadOnly Property NBSINISTRESGLOBAL As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim data As New ArrayList
                    With Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.ProjectionGenNAnnuelle
                        For i As Integer = 0 To .NbSinDC.Length - 1
                            data.Add(New SimplePoint(i + startyear, .NbSinDC(i) + .NbSinINCINV(i)))
                        Next
                    End With
                    Return data
                Catch ex As Exception
                    '  Return TestData.SimpleData
                End Try
            End Get
        End Property
        Public ReadOnly Property NBSINISTRESDC As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim data As New ArrayList
                    With Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.ProjectionGenNAnnuelle
                        For i As Integer = 0 To .NbSinDC.Length - 1
                            data.Add(New SimplePoint(i + startyear, .NbSinDC(i)))
                        Next
                    End With
                    Return data
                Catch ex As Exception
                    ' Return TestData.SimpleData
                End Try
            End Get
        End Property
        Public ReadOnly Property NBSINISTRESINCAP As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim data As New ArrayList
                    With Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.ProjectionGenNAnnuelle
                        For i As Integer = 0 To .NbSinDC.Length - 1
                            data.Add(New SimplePoint(i + startyear, .NbSinINCINV(i)))
                        Next
                    End With
                    Return data
                Catch ex As Exception
                    '  Return TestData.SimpleData
                End Try
            End Get
        End Property

        Private Shared rnd As New Random(Now.Millisecond)

        Public ReadOnly Property TOPRIGHTGRAPHDATAGLOBAL As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim yearcount As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.NombreAnneesProjection
                    Dim indicateurs = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteIndicateur
                    Dim crtvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTVie
                    Dim crtnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTNonVie
                    Dim ctvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.CompteTechniqueVie
                    Dim ctnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.CompteTechniqueNonVie
                    Dim parametres = Locator.ModelStatic.ListeParametres
                    Dim factor = 1 - parametres.Tx_fraiGestA.ValeurUnique - parametres.Tx_CommiContA.ValeurUnique
                    Dim taxe_assu = parametres.Tx_TaxeAssu.ValeurUnique


                    Return From e In Enumerable.Range(0, yearcount)
                           Select X = startyear + e,
                                  Y1 = crtvie.PrimesDC(e) + crtnonvie.PrimesIT(e),
                                  Y2 = factor * (crtvie.PrimesDC(e) + (crtnonvie.PrimesIT(e) / (1 + taxe_assu))),
                                  Y3 = crtvie.SinRegles(e) + crtnonvie.SinReglesIT(e),
                                  Y4 = ctnonvie.ParametresEntree.PmITclotTheo(e) + ctvie.ParametresEntree.PmDCclotTheo(e)

                Catch ex As Exception
                    Return Nothing

                    Return From e In Enumerable.Range(2010, 15)
                               Select X = e,
                                      Y1 = CDbl((e - 2017) * (e - 2022)),
                                      Y2 = CDbl((e - 2017) * (e - 2013)),
                                      Y3 = CDbl((e - 2010) * (e - 2025)),
                                      Y4 = CDbl((e - 2022) * (e - 2013))

                End Try
            End Get
        End Property
        Public ReadOnly Property TOPRIGHTGRAPHDATADC As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim yearcount As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.NombreAnneesProjection
                    Dim indicateurs = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteIndicateur
                    Dim crtvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTVie
                    Dim crtnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTNonVie
                    Dim ctvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.CompteTechniqueVie
                    Dim ctnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.CompteTechniqueNonVie
                    Dim parametres = Locator.ModelStatic.ListeParametres
                    Dim factor = 1 - parametres.Tx_fraiGestA.ValeurUnique - parametres.Tx_CommiContA.ValeurUnique
                    Dim taxe_assu = parametres.Tx_TaxeAssu.ValeurUnique

                    Return From e In Enumerable.Range(0, yearcount)
                           Select X = startyear + e,
                                  Y1 = crtvie.PrimesDC(e),
                                  Y2 = factor * crtvie.PrimesDC(e),
                                  Y3 = crtvie.SinRegles(e),
                                  Y4 = ctvie.ParametresEntree.PmDCclotTheo(e)

                Catch ex As Exception
                    Return Nothing
                    Return From e In Enumerable.Range(2010, 15)
                               Select X = e,
                                      Y1 = CDbl((e - 2017) * (e - 2022)),
                                      Y2 = CDbl((e - 2017) * (e - 2013))

                End Try
            End Get
        End Property
        Public ReadOnly Property TOPRIGHTGRAPHDATAINCAP As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim yearcount As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.NombreAnneesProjection
                    Dim indicateurs = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteIndicateur
                    Dim crtvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTVie
                    Dim crtnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTNonVie
                    Dim ctvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.CompteTechniqueVie
                    Dim ctnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.CompteTechniqueNonVie
                    Dim parametres = Locator.ModelStatic.ListeParametres
                    Dim factor = 1 - parametres.Tx_fraiGestA.ValeurUnique - parametres.Tx_CommiContA.ValeurUnique
                    Dim taxe_assu = parametres.Tx_TaxeAssu.ValeurUnique

                    Return From e In Enumerable.Range(0, yearcount)
                           Select X = startyear + e,
                                  Y1 = crtnonvie.PrimesIT(e),
                                  Y2 = factor * crtnonvie.PrimesIT(e) / (1 + taxe_assu),
                                  Y3 = crtnonvie.SinReglesIT(e),
                                  Y4 = ctnonvie.ParametresEntree.PmITclotTheo(e)

                Catch ex As Exception
                    Return From e In Enumerable.Range(2010, 15)
                               Select X = e,
                                      Y1 = CDbl((e - 2017) * (e - 2022)),
                                      Y2 = CDbl((e - 2017) * (e - 2013))

                End Try
            End Get
        End Property


        Public ReadOnly Property BOTTOMRIGHTGRAPHDATAGLOBAL As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim yearcount As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.NombreAnneesProjection
                    yearcount -= 1
                    Dim indicateurs = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteIndicateur
                    Dim crtvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTVie
                    Dim crtnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTNonVie

                    Return From e In Enumerable.Range(0, yearcount)
                           Select X = startyear + e,
                                  Y1 = indicateurs.SP_techTot(e),
                                  Y2 = (crtvie.SinRegles(e) + crtnonvie.SinReglesIT(e)) _
                                           / _
                                       (crtvie.PrimesDC(e) + crtnonvie.PrimesIT(e))


                Catch ex As Exception
                    Return Nothing
                    Return From e In Enumerable.Range(2010, 15)
                               Select X = e,
                                      Y1 = CDbl((e - 2017) * (e - 2022)),
                                      Y2 = CDbl((e - 2017) * (e - 2013))

                End Try
            End Get
        End Property
        Public ReadOnly Property BOTTOMRIGHTGRAPHDATADC As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim yearcount As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.NombreAnneesProjection
                    yearcount -= 1
                    Dim indicateurs = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteIndicateur
                    Dim crtvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTVie
                    Dim crtnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTNonVie

                    Return From e In Enumerable.Range(0, yearcount)
                           Select X = startyear + e,
                                  Y1 = indicateurs.SP_techDC(e),
                                  Y2 = crtvie.SinRegles(e) / crtvie.PrimesDC(e)

                Catch ex As Exception
                    Return Nothing
                    Return From e In BOTTOMRIGHTGRAPHDATAGLOBAL
                        Select X = e.X,
                               Y1 = Math.Log(Math.Abs(e.Y1) + 1),
                               Y2 = Math.Log(Math.Abs(e.Y2) + 1)
                End Try
            End Get
        End Property
        Public ReadOnly Property BOTTOMRIGHTGRAPHDATAINCAP As IEnumerable
            Get
                Try
                    Dim startyear As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.AnneePremiereGeneration
                    Dim yearcount As Integer = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.Comptes.NombreAnneesProjection
                    yearcount -= 1
                    Dim indicateurs = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteIndicateur
                    Dim crtvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTVie
                    Dim crtnonvie = Locator.ModelStatic.ListeTraitements.TraitMoteurMethode2.scenarioCentral.resultats.compteCRTNonVie

                    Return From e In Enumerable.Range(0, yearcount)
                           Select X = startyear + e,
                                  Y1 = indicateurs.SP_techINCINV(e),
                                  Y2 = crtnonvie.SinReglesIT(e) / crtnonvie.PrimesIT(e)

                Catch ex As Exception
                    Return Nothing
                    Return From e In BOTTOMRIGHTGRAPHDATADC
                             Select X = e.X,
                                    Y1 = (e.Y1 * e.Y1) / (1 + (e.Y2 * e.Y2)),
                                    Y2 = (0.75 + 0.5 * rnd.NextDouble()) * (e.Y1 * e.Y1) / (1 + (e.Y2 * e.Y2))

                End Try
            End Get
        End Property


        Private _YearAxisUnit As Double = Double.NaN
        Private _YearAxisMinimum As Double = Double.NaN
        Private _YearAxisMaximum As Double = Double.NaN

        Public Property YearAxisUnit As Double
            Get
                Return _YearAxisUnit
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("YearAxisUnit")
                _YearAxisUnit = value
                OnPropertyChanged("YearAxisUnit")
            End Set
        End Property
        Public Property YearAxisMinimum As Double
            Get
                Return _YearAxisMinimum
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("YearAxisMinimum")
                _YearAxisMinimum = value
                OnPropertyChanged("YearAxisMinimum")
            End Set
        End Property
        Public Property YearAxisMaximum As Double
            Get
                Return _YearAxisMaximum
            End Get
            Set(ByVal value As Double)
                OnPropertyChanging("YearAxisMaximum")
                _YearAxisMaximum = value
                OnPropertyChanged("YearAxisMaximum")
            End Set
        End Property
        Public ReadOnly Property AutoAxis As Boolean
            Get
                Return _
                    Double.IsNaN(_YearAxisUnit) Or _
                    Double.IsNaN(_YearAxisMinimum) Or _
                    Double.IsNaN(_YearAxisMaximum)
            End Get
        End Property
        Private Sub ResetYearAxis(ByVal unit As Double, ByVal min As Double, ByVal max As Double)
            If AutoAxis Then
                _YearAxisUnit = unit
                _YearAxisMinimum = min
                _YearAxisMaximum = max

                OnPropertyChanged("YearAxisMaximum")
                OnPropertyChanged("YearAxisMinimum")
                OnPropertyChanged("YearAxisUnit")
                OnPropertyChanged("AutoAxis")
            End If
        End Sub

    End Class
End Namespace